import { Component, OnInit } from '@angular/core';

// 导入路由服务
import { Router,ActivatedRoute } from '@angular/router';

// 导入storage服务
import { StorageService } from '../../service/storage.service';

@Component({
  selector: 'app-contact-add',
  templateUrl: './contact-add.component.html',
  styleUrls: ['./contact-add.component.css']
})
export class ContactAddComponent implements OnInit {

  private tagList:Array<{id:number,name:string}>;

  constructor(
    private router:Router,
    private routes:ActivatedRoute,
    private storage:StorageService,
  ) { }

  ngOnInit() {
    this.tagList=this.storage.tagList;
  }

  // 新增联系人
  addHandle(f):void{
    if(!f.valid){
      return alert('请输入完整的表单信息');
    }
    this.storage.contactAdd(f.value);
    // 清空表单元素的值
    for(let key in f) f[key]='';
    alert('新增成功');
    this.router.navigate(['contactlist']);
  }

}
